<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #banner {
            width: 900px;
            margin: 0 auto;
            position: relative;
            margin-top: 20px;
            height: 360px;
            overflow: hidden;
        }
        #banner > img{
            width: 900px;
            display: block;
            position: absolute;
            left: 0;
            z-index: -1;
        }
    </style>
</head>
<body>
    <div id="banner">
        <img src="./image/1 (1).jpg" alt="" title="点击显示详情">
        <img src="./image/1 (2).jpg" title="1dfag">
        <img src="./image/1 (3).jpg" title="1dfa">
        <img src="./image/1 (4).jpg" title="1gac">
        <img src="./image/1 (5).jpg" title="1vzvz">
    </div>
</body>
<script>
    // 轮播图js代码
    var banner = document.getElementById("banner");
    var imgs = banner.querySelectorAll("img");
    console.log(imgs);
    for(var i = 0; i < imgs.length; i++){
        imgs[i].style.left = 900*i + "px";
    }
    function time1Inter(){
        var speed = 5;
        for(var i = 0; i < imgs.length; i++){
            var left = parseInt(imgs[i].style.left) - speed;
            imgs[i].style.left = left + "px";
            if(parseInt(imgs[i].style.left) <= -900){
                imgs[i].style.left = 3600 + "px";
                clearInterval(time1);
            }
        }
        
    }
    var time1;
    var time2;

    setTimeout(function(){
        time2 = setInterval(function(){
            clearInterval(time1);
            time1 = setInterval(time1Inter,5);
        }, 4000);
    },100);

    banner.onmouseover = function(){
        clearInterval(time2);
    }
    banner.onmouseout = function(){
        clearInterval(time2);
        time2 = setInterval(function(){
            clearInterval(time1);
            time1 = setInterval(time1Inter,5);
        }, 4000);
    }

    // 轮播图js代码结束
</script>
</html>